package com.ai3d.rfid.network.download

import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

/**
 * author: weijinsong
 * date: 2020/10/13
 * desc:
 */
class DownloadInterceptor(IDownloadListener: IDownloadListener) : Interceptor {
    private val mIDownloadListener: IDownloadListener
    @kotlin.jvm.Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val response: Response = chain.proceed(chain.request())
        return response.newBuilder().body(response.body()
            ?.let { ResponseBodyListener(it, mIDownloadListener) })
            .build()
    }

    init {
        mIDownloadListener = IDownloadListener
    }
}